package com.baigt.juc.base;

import java.util.concurrent.TimeUnit;

/**
 * 类功能描述:
 * 线程异常处理机制
 *
 * @author baigt
 * @version V1.0
 * @since 2019-10-21 10:25
 */
public class ThreadRun07 {
    /**
     * java.lang.ThreadGroup#uncaughtException(java.lang.Thread, java.lang.Throwable)
     * @param args
     * @throws InterruptedException
     */
    public static void main(String[] args) throws InterruptedException {
        Thread.setDefaultUncaughtExceptionHandler((thread, exception) -> {
            System.out.println(thread.getName() + ":" + exception.getMessage());
            System.out.println("--------------------------");
            exception.printStackTrace();
        });

        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            int i = 1 / 0;
        }).start();
    }

}
